/**
 * Copyright (c) 2019-2029, wwww.kiwipeach.cn (liuburu@qq.com).
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * <p>
 * https://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package cn.kiwipeach.blog;

import cn.kiwipeach.blog.utils.SpringUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.web.servlet.Cookie;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.transaction.annotation.EnableTransactionManagement;


/**
 * 持久层启动类入口
 *
 * @author kiwipeach
 * @since 1.0
 */
@EnableTransactionManagement
@SpringBootApplication(scanBasePackages = {"cn.kiwipeach.blog"})
@EnableCaching
@MapperScan(value = {"cn.kiwipeach.blog.generator.mapper", "cn.kiwipeach.blog.mapper"})
@Slf4j
public class BlogWebApplication extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(BlogWebApplication.class);
    }

    public static void main(String[] args) {
        SpringApplication app = new SpringApplication(BlogWebApplication.class);
        app.setBannerMode(Banner.Mode.CONSOLE);
        app.run(args);
        Cookie cookie = SpringUtil.getBean("shiroCookie", Cookie.class);
        afterLauchAction(cookie);
    }

    private static void afterLauchAction(Cookie cookie) {
        String domain = cookie.getDomain();
        String indexUrl = String.format("http://%s", domain);
        log.warn("系统首页:{}", indexUrl);
        log.warn("Swagger文档:http://{}/swagger-ui.html", domain);
        log.warn("Druid监控:http://{}/druid", domain);
        /*try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
        } finally {
            SystemRuntimeUtil.browerOpen(indexUrl);
        }*/
    }


}
